import { Body, Controller, Delete, Get, Param, Post, Query, UseGuards, UsePipes } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { LoginLogService } from './login-log.service';
import { ZodValidationPipe } from '../../common/pipes/zod-validation.pipe';
import { pageQuerySchema } from './dto/login-log.schema';
import { RequiresPermissions } from '../../common/decorators/requires-permissions.decorator';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('loginInfo-登录日志模块')
@Controller('logininfo')
@UseGuards(JwtAuthGuard)
export class LoginLogController {
  constructor(private readonly loginLogService: LoginLogService) { }

  /**
   * 分页查询登录日志
   */
  @Get('list')
  @RequiresPermissions('system:logininfor:list')
  @UsePipes(new ZodValidationPipe(pageQuerySchema))
  async findByPage(@Query() query) {
    return this.loginLogService.findByPage(query);
  }

  /**
   * 删除登录日志
   */
  @Delete(':ids')
  @RequiresPermissions('system:logininfor:remove')
  async remove(@Param('ids') idsStr: string) {
    const ids = idsStr.split(',').map(id => parseInt(id, 10));
    return this.loginLogService.remove(ids);
  }

  /**
   * 清空登录日志
   */
  @Delete('clean')
  @RequiresPermissions('system:logininfor:remove')
  async clean() {
    return this.loginLogService.clear();
  }
} 